﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ctolua.Models.System
{
    public static class SCache
    {
        public static Dictionary<dynamic, dynamic> cacheKV=new Dictionary<dynamic, dynamic> ();
        public static T? getCache<T>(dynamic k)
        {
            dynamic v;
            if (cacheKV.TryGetValue(k, out v))
            {
                return v;
            }
            else
            {
                return default(T);
            }

        }
        public static void setCache(dynamic k,dynamic v)
        {
            dynamic c;
            if (!cacheKV.TryGetValue(k, out c))
            {
                cacheKV.Add(k, v);
            }
        }
        public static void setUICache(dynamic p, dynamic id, dynamic v)
        {
            setCache($"UI{p}{id}", v);
        }
        public static T? getUICache<T>(dynamic p, dynamic id)
        {
            return getCache<T>($"UI{p}{id}");

        }
        public static void setUnitCache(dynamic k, dynamic v)
        {
            setCache($"Unit{k}", v);
        }
        public static T? getUnitCache<T>(dynamic k)
        {
            return getCache<T>($"Unit{k}");
        }
        public static void setUnitDIYCache(dynamic k, dynamic v)
        {
            setCache($"Unit独立{k}", v);
        }
        public static T? getUnitDIYCache<T>(dynamic k)
        {
            return getCache<T>($"Unit独立{k}");
        }
        public static void setItemCache(dynamic k, dynamic v)
        {
            setCache($"Item{k}", v);
        }
        public static T? getItemCache<T>(dynamic k)
        {
            return getCache<T>($"Item{k}");
        }
        public static void setItemDIYCache(dynamic k, dynamic v)
        {
            setCache($"Item独立{k}", v);
        }
        public static T? getItemDIYCache<T>(dynamic k)
        {
            return getCache<T>($"Item独立{k}");
        }

        public static void setTimeCache(dynamic k, dynamic v)
        {
            setCache($"Time{k}", v);
        }
        public static T? getTimeCache<T>(dynamic k)
        {
            return getCache<T>($"Time{k}");
        }
        public static void setAbilityCache(dynamic k, dynamic v)
        {
            setCache($"Ability{k}", v);
        }
        public static T? getAbilityCache<T>(dynamic k)
        {
            return getCache<T>($"Ability{k}");
        }
    }
}
